package com.kczd.jinlan.adapter.recycleviewadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kczd.jinlan.R;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>  {

    private Context mContext;
    private List<String> dataList = new ArrayList<>();


    public void addAllData(List<String> dataList) {
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }

    public void clearData() {
        this.dataList.clear();
    }

    public RecyclerViewAdapter(Context context) {
        mContext = context;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView title;
        TextView beizhu;
        TextView price;
        TextView oldprice;
        ImageView gouwuche;
        ImageView imgshop;


        public ViewHolder(View view) {
            super(view);
            title = (TextView) view.findViewById(R.id.tv_title);
            beizhu = (TextView) view.findViewById(R.id.beizhu);
            price = (TextView) view.findViewById(R.id.id_price);
            oldprice = (TextView) view.findViewById(R.id.textView);
            gouwuche= (ImageView) view.findViewById(R.id.imageView);
            imgshop= (ImageView) view.findViewById(R.id.img);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_base, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.title.setText(dataList.get(position));
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }


}